import { Table } from './table';
import { TableParty } from './tableParty';
import { Checkout } from './checkout';
import { Cart } from './cart';
import { EntityObjectFactory } from './../entityObjectFactory';
let EntityObject = EntityObjectFactory.GetEntityObjectType();

export class Order extends EntityObject<Order> {
    constructor(ctx?) { super(ctx); }
    id: string = null;
    amountDue: number = 0;
    cart: Cart = <any>{};
    cashier = null;
    cashierId: string = null;
    checkout: Checkout = null;
    checkoutMode: string = null;
    closeTime: number = null;
    createTime: number = null;
    creator: { id: string, name: string } = null;
    creatorId: string = null;
    member: Member = null;
    memberType: MemberType = null;
    memberId:string = null;
    discount: number = null;
    discounts: Array<any> = null;
    headCount: number = null;
    lastPrintTime: number = null;
    orderDiscount: number = null;
    orderNo: string = null;
    orderType: string = null;
    paidAmount: number = null;
    payments: Payments[] = null;
    printCount = null;
    refundAmount: number = null;
    refundCause: string = null;
    remainAmount: number = null;
    serialNo: string = null;
    refOrderId = null;
    smallChangeOff: number = null;
    status: string = null;
    storeId: string = null;
    subtotal: number = 0;
    terminalName: string = null;
    total: number = 0;
    sourceid: string = null;
    processStatus: ProcessStatus = null;
    extended: OrderExtended = null;
    description: string = null;
    openid: string = null;
    master: string = null;
    cancelPreSettledCount: number = null;
    isCounter:boolean = null;
    counterRemark:string = null;

    toString() { return "Orders"; }
}

export class WorkflowOrder extends Order {
    toString() { return "workflow"; }
}

interface OrderExtended {
    headCount?: number;
    table?: Table;
    tableParty?: TableParty;
    remind?: Remind;
    numberPlate?: number;
    lastRemindTime?: number;
    canelPerSettled?: {
        operator?: { id: string; name: string };
        operateTime?: number;
        remark?: string;
        befroeAmount?: number;
    }[];
    waiter?:{id:string,name:string}[];
    mpointsTx?:{pointsBefore:number};
    acctTx?:{balance:string};
}

interface Remind {
    remindTime: Date;
    operator: { id: string, name: string };
    remindCount: number;
}

export interface Payments {
    id: string;
    amount: number;
    channel: string;    // 支付方式
    channelId: string;  // 支付类型id
    charge: number;     // 找零
    createTime: number;
    payMode: string;    // 交易类型：pay 消费/ refund 退款
    received: number;   // 实收
    refunded: boolean;  // 是否已退
    storeId: string;    // 商铺Id
    extended: string;   // 扩展信息，用于包括支付所需记录的详细内容，或者其他内容。JSON格式
    orderNo: string;    // 订单号
    status: string;      // 支付状态
}

interface ProcessStatus {
    id: string;
    orderNo: string;
    statusType: string;
    status: string;
    detail: Detail[];
}

interface Detail {
    id: string;
    orderNo: string;
    statusType: string;
    status: string;
    createTime: number;
}

interface Member {
    id: string;
    account;
    binds;
    createTime: number;
    creator: { email: string; id: string; mobile: string; name: string; pic: string; sex: string };
    joinDate: number;
    memberType;
    merchant: { id: string; };
    mgmtZDomain: string;
    mobile: string;
    name: string;
    searchCode: string;
    sex: string;
    store: any;
}

interface MemberType {
    id: string;
    name: string;
    setting;
    showOrder: number;
    style;
    discountRule: { id: string; name: string; definition: { discountFactor: number } };
}